package com.woniuxy.food.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodpicclient.FoodPicQueryClient;
import com.woniuxy.food.client.result.FoodPicClientDto;
import com.woniuxy.food.service.FoodPicService;
import com.woniuxy.food.service.servicedto.FoodPicServiceDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import java.util.List;

@RestController
public class FoodPicQueryClientApiImpl implements FoodPicQueryClient {
    @Autowired
    private FoodPicService foodPicService;
    @Override
    @Log("查询全部图片")
    public Result<List<FoodPicClientDto>> searchFoodPic(Integer storeId) {
        List<FoodPicServiceDto> foodPicServiceDtos = foodPicService.searchFoodPic(storeId);
        List<FoodPicClientDto> foodPicClientDtos = BeanUtil.copyToList(foodPicServiceDtos, FoodPicClientDto.class);
        return Result.success(foodPicClientDtos);
    }

    @Override
    @Log("根据ID查询图片")
    public Result<FoodPicClientDto> searchFoodPicById(Integer storeId, Integer foodPicId) {
        FoodPicServiceDto foodPicServiceDto = foodPicService.searchFoodPicById(storeId, foodPicId);
        FoodPicClientDto foodPicClientDto = BeanUtil.toBean(foodPicServiceDto, FoodPicClientDto.class);
        return Result.success(foodPicClientDto);
    }
}
